package primalgorithms.array;

public class _03TurnArray {
    public static void rotate(int[] nums, int k) {
        if(nums == null || nums.length == 0){
            return;
        }
        //防止数组下标越界
        while (k >= nums.length){
            k -= nums.length;
        }
        //临时数组
        int[] reNums = new int[nums.length];
        for(int i = 0;i < nums.length;i++){
            if(k < nums.length){
                reNums[k++] = nums[i];
            }else {
                reNums[k-nums.length] = nums[i];
                k++;
            }
        }
        for (int i = 0;i < nums.length;i++){
            nums[i] = reNums[i];
        }
    }
}
